﻿using System;
using System.Collections;
using System.Data;

public partial class Admin_News_QL_BieuMauDetail : System.Web.UI.Page
{
    Data data = new Data();
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["admin"].Equals("true") == false)
            {
                Response.Redirect("../Default.aspx");
            }
            else
            {
                FillNoiDung();
            }
        }
        catch (Exception)
        {
            Response.Redirect("../Default.aspx");
            throw;
        }
    }

    private void FillNoiDung()
    {
        if (Request.QueryString["delete"] != null)
        {
            data.Delete_BieuMauDetail(Request.QueryString["delete"]);
        }
        if (IsPostBack == false)
        {
            DataTable table = data.GetTable_By_Name("BieuMauCate");
            DropDownList1.DataSource = table;
            DropDownList1.DataTextField = "CategoryName";
            DropDownList1.DataValueField = "CategoryID";
            DropDownList1.DataBind();
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            data.Add_BieuMauDetail(DropDownList1.SelectedValue, txtNAme.Text, FileUpload1.FileName);
            FileUpload1.SaveAs(Server.MapPath("~/Images/FileBieuMau/") + FileUpload1.FileName);
            btnChon_Click(sender, e);
        }
    }
    protected void BtnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
    protected void btnChon_Click(object sender, EventArgs e)
    {
         DataTable table = data.GetTable_By_Where("BieuMau","where CategoryID=" + DropDownList1.SelectedValue);
         DataListYahoo.DataSource = table;
         DataListYahoo.DataBind();
    }
}
